package com.zxy.express.dto;

import com.autopai.base.common.tools.utils.JsonUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import lombok.Data;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.StringUtils;


/**
 * 合集下的单集
 *
 * @author zhangxiying ${email}
 * @since ${version} 2025-07-01
 */
@Data
@ApiModel(value = "合集下的单集")
public class AudioEpisodeDTO implements Serializable {
    private static final long serialVersionUID = 1L;

	@ApiModelProperty(value = "主键ID")
	private Long id;

	@ApiModelProperty(value = "所属分类ID")
	private Long categoryId;
	
	@ApiModelProperty(value = "所属合集ID")
	private Long collectionId;

	@ApiModelProperty(value = "素材标题")
	private String title;

	@ApiModelProperty(value = "素材原始纯文本内容")
	private String content;

	@ApiModelProperty(value = "带时间戳的文本内容 (用于字幕同步)")
	private String timedContent;

	@ApiModelProperty(value = "范读音频文件URL")
	private String audioUrl;

	@ApiModelProperty(value = "难度 (1:初级, 2:中级, 3:高级)")
	private Integer difficulty;

	@ApiModelProperty(value = "预计练习时长（单位：秒）")
	private Integer duration;

	@ApiModelProperty(value = "练习人次统计")
	private Integer practiceCount;

	@ApiModelProperty(value = "是否启用")
	private Integer isActive;

	@ApiModelProperty(value = "创建时间")
	private Date createDate;

	@ApiModelProperty(value = "")
	private Date updateDate;

	private Integer sort;

	public static void main(String[] args) {
//		"[\n" +
//				"  {\n" +
//				"    \"id\": 1,\n" +
//				"    \"start\": 0.5,\n" +
//				"    \"end\": 2.8,\n" +
//				"    \"text\": \"在现代社会，无论是职场沟通、公开演讲还是日常交流，\"\n" +
//				"  },\n" +
//				"  {\n" +
//				"    \"id\": 2,\n" +
//				"    \"start\": 3.0,\n" +
//				"    \"end\": 5.5,\n" +
//				"    \"text\": \"清晰、流畅、有逻辑的表达能力都是一项至关重要的核心技能。\"\n" +
//				"  },\n" +
//				"  {\n" +
//				"    \"id\": 3,\n" +
//				"    \"start\": 5.8,\n" +
//				"    \"end\": 9.2,\n" +
//				"    \"text\": \"然而，许多人缺乏系统性的刻意练习环境和科学的反馈机制。\"\n" +
//				"  }\n" +
//				"]"
		String content="1\n" +
				"\t\t00:00:00,000 --> 00:00:03,366\n" +
				"\t\t小男孩奇奇听爷爷讲胡服骑射\n" +
				"\n" +
				"\t\t2\n" +
				"\t\t00:00:03,366 --> 00:00:06,433\n" +
				"\t\t赵武灵王穿胡服练骑射\n" +
				"\n" +
				"\t\t3\n" +
				"\t\t00:00:06,433 --> 00:00:08,133\n" +
				"\t\t国家变强大\n" +
				"\n" +
				"\t\t4\n" +
				"\t\t00:00:08,133 --> 00:00:10,733\n" +
				"\t\t奇奇懂了要学习新事物\n" +
				"\n" +
				"\t\t5\n" +
				"\t\t00:00:10,733 --> 00:00:13,400\n" +
				"\t\t他也要勇敢尝试新本领";

		String[] lines = content.split("\n");
		int lent= lines.length;
		List<TimedContentDTO> dtos= Lists.newArrayList();
		for (int i = 0; i < lent;) {
			if(StringUtils.isEmpty(lines[i])){
				i++;
				continue;
			}
			int id=Integer.parseInt(lines[i].trim().replaceAll("\n",""));
			i=i+1;
			String[] strs=lines[i].split("-->");
			String start=strs[0].trim().replaceAll("\t","");
			String[] starts=start.split(":|,");
			double  startTime=Integer.parseInt(starts[0])*60*60+Integer.parseInt(starts[1])*60+Integer.parseInt(starts[2])+Integer.parseInt(starts[3])/1000.0;
			TimedContentDTO dto=new TimedContentDTO();
			dto.setId(id);
			dto.setStart(Float.parseFloat(String.format("%.1f",startTime)));
			String end=strs[1].trim().replaceAll("\t","");
			starts=end.split(":|,");
			double endTime=Integer.parseInt(starts[0])*60*60+Integer.parseInt(starts[1])*60+Integer.parseInt(starts[2])+Integer.parseInt(starts[3])/1000.0;
			dto.setEnd(Float.parseFloat(String.format("%.1f",endTime)));
			i=i+1;
			dto.setText(lines[i].trim().replaceAll("\t",""));
			dtos.add(dto);
			i=i+1;

		}
		System.out.println(JsonUtil.obj2String(dtos));

	}

}